package com.llg.util;

import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;

@SuppressWarnings(value = "all")
public class ConvertUtils {


    public static <T> List<T> povoListConvert(List list, Class<T> clazz) {
        List<T> collect = (List<T>) list.stream().map(po -> {
            T t = null;
            try {
                t = clazz.newInstance();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
            BeanUtils.copyProperties(po, t);
            return t;
        }).collect(Collectors.toList());
        return collect;
    }

    public static <T> T povoConvert(Object o, Class<T> clazz) {
        T t = null;
        try {
            t = clazz.newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        BeanUtils.copyProperties(o, t);
        return t;
    }




}
